package com.survey.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.survey.bean.QuesItemList;
import com.survey.bean.QuesItemListOptionAnswer;
import com.survey.bean.QuesUser;
import com.survey.util.common.BaseService;
import com.survey.dao.QuesItemListOptionAnswerMapper;
import com.survey.dao.QuesItemListOptionMapper;
import com.survey.dao.QuesUserMapper;
import com.survey.dao.SQLMapper;

@Service
@Transactional
public class QuesUserService extends BaseService<QuesUser> {
	@Autowired
	QuesUserMapper									quesUserMapper;
	@Autowired
	QuesItemListOptionAnswerMapper	quesItemListOptionAnswerMapper;
	@Autowired
	QuesItemListOptionMapper				quesItemListOptionMapper;
	@Autowired
	SQLMapper												sqlMapper;

	public void addQuesUser(QuesUser bean, List<QuesItemList> list, List<QuesItemListOptionAnswer> anslist) {
		quesUserMapper.insert(bean);
		for (QuesItemList itemList : list) {
			if (itemList.getTypesel().equals("单选")) {
				String v = (String) itemList.getUserchose();
				sqlMapper.updateAmount(Integer.valueOf(v));
			} else if (itemList.getTypesel().equals("多选")) {
				String[] v = (String[]) itemList.getUserchose();
				for (String s : v) {
					sqlMapper.updateAmount(Integer.valueOf(s));
				}
			}
		}
		for (QuesItemListOptionAnswer quesItemListOptionAnswer : anslist) {
			quesItemListOptionAnswerMapper.insert(quesItemListOptionAnswer);
		}
	}

}
